<?php

namespace App\Http\Controllers\Merchant;

use App\CommissionConfig;
use App\Http\Response;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CommissionConfigController extends Controller
{
    use Response;
    public function index(Request $request)
    {
        $list=CommissionConfig::where('mch_id',auth('merchant')->id())->paginate($request->get('pageSize'),'*','pageNo');
        return $this->success(200,$list);
    }

    public function store(Request $request)
    {
        $request->merge(['mch_id'=>$request->header('mch_id',1)]);
        $created=CommissionConfig::create($request->all());
        if ($created){
            return $this->message(200,trans('topic.create success'));
        }else{
            return $this->message(505,trans('topic.create failed'));
        }
    }
    public function show($id)
    {
        $data=CommissionConfig::find($id);
        return $this->success(200,$data);
    }
    public function update($id,Request $request)
    {
        $update=CommissionConfig::where('id',$id)->update($request->all());
        if ($update){
            return $this->message(200,trans('topic.update success'));
        }else{
            return $this->error(505,trans('topic.update failed'));
        }
    }
    public function destroy(Request $request)
    {
        $delete=CommissionConfig::destroy($request->get('id'));
        if ($delete){
            return $this->message(200,trans('topic.delete success'));
        }else{
            return $this->error(505,trans('topic.delete failed'));
        }
    }
}
